
var time = require("../../utils/util.js");
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    type: [{
      num: "4",
      text: "全部"
    },{
      num: "2",
      text: "已提交"
    },{
      num: "0",
      text: "已处理"
    },{
      num: "0",
      text: "审核未通过"
    }],
    typeindex: 0,
    list: [],
    pageNum: 1,
    pageSize: 10,
    widheight: ''
  },
  bindtype(e) {
    console.log(e);
    
  },
  onChange(event) {
    var that = this;
    console.log(event)
    that.setData({
      typeindex: event.detail.index,
      pageNum: 1,
    })
    wx.request({     //辖区
      url: time.httpurl + '/api/getOrderList?pageNum=' + that.data.pageNum + '&pageSize=' + that.data.pageSize,
      method: 'POST',
      data: {
        status: event.detail.index,
      },
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        console.log(res,'list');
        if(res.data.code == 200){
          that.setData({
            list: res.data.rows
          })
          that.setData({
            total: res.data.total
          })
        }else if(res.data.code == 401 || res.data.code == 403){
          app.login();
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }     
      }
    })
  },
  getdel: function(event){
    console.log(event);
    if(event.currentTarget.dataset.id != undefined){
      wx.navigateTo({
        url: '../details/details?orderid=' + event.currentTarget.dataset.id + '&typename=' + event.currentTarget.dataset.typename,
      })
    }    
  },
  onGoodsScroll: function(e){
    var that = this;
    console.log(e,that.data.pageNum,Math.ceil(that.data.total/that.data.pageSize),that.data.typeindex);
    if(that.data.pageNum < Math.ceil(that.data.total/that.data.pageSize)){
      that.setData({
        pageNum: that.data.pageNum + 1
      })
      wx.request({     
        url: time.httpurl + '/api/getOrderList?pageNum=' + that.data.pageNum + '&pageSize=' + that.data.pageSize,
        method: 'POST',
        data: {
          status: that.data.typeindex
        },
        header: {
          'AppType': 'AppType',
          'Authorization': wx.getStorageSync("token"),
        },
        success: function (res) {
          console.log(res,'list');
          if(res.data.code == 200){
            that.setData({
              list: that.data.list.concat(res.data.rows)
            })
          }else if(res.data.code == 401 || res.data.code == 403){
            app.login();
          }else{
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }     
        }
      })
    }   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          widheight: res.screenHeight - 130,
          pageSize: Math.ceil((res.screenHeight - 60)/80)
        });
        wx.request({     
          url: time.httpurl + '/api/getOrderList?pageNum=' + that.data.pageNum + '&pageSize=' + that.data.pageSize,
          method: 'POST',
          data: {
            status: that.data.typeindex,
          },
          header: {
            'AppType': 'AppType',
            'Authorization': wx.getStorageSync("token"),
          },
          success: function (res) {
            console.log(res,'list');
            if(res.data.code == 200){
              that.setData({
                list: res.data.rows
              })
              that.setData({
                total: res.data.total
              })
            }else if(res.data.code == 401 || res.data.code == 403){
              app.login();
            }else{
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
            }     
          }
        })
      }
    });
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})